/**
 * @auth	or joshua
 */
Ext.ns('joshua.Login');//name Space
joshua.Login.Form=Ext.extend(Ext.Panel,{
	border:false,
	bodyStyle:'padding:5px 0px 0px 5px; background:#000000; color:#ffffff',
	autoWidth:true,
	frame:false,
	buttonAlign:'right',
    defaults: {width:100},
	layout:'form',	
	initComponent:function(){
		var config={
			txtUsuario:new Ext.form.TextField({
							fieldLabel:'Usuario',
							//allowBlank:false,
								//             value:'tioche'
							name: 'txtId'//,
                                           
						}),
			txtPass:new Ext.form.TextField({
							fieldLabel:'Contrase&#241a',
							//allowBlank:false,
							name: 'pwd_pass',
                                            //            value:'alumnoss',
							inputType:'password',
							listeners:{
								scope:this,
								specialkey:function(field,e){if(e.getKey()==e.ENTER)this.mandarForm();}
							}
			})
		}//fin config
	Ext.apply(this,Ext.apply(this.initialConfig,config));
		//establecemos la configuracion por default
	this.items=[this.txtUsuario,this.txtPass];
	this.buttons=[{
					text:'<b>Entrar</br>',
					iconCls:'aceptar',
					scope:this,
					handler:function(){						
						this.mandarForm();
					}
		}]	
	joshua.Login.Form.superclass.initComponent.apply(this,arguments);
	},//fin init
	//onRender
 	onRender:function(){
 		joshua.Login.Form.superclass.onRender.apply(this,arguments);
 		this.txtUsuario.focus('', 10);
 	},
 	mandarForm:function(){
 			this.getEl().mask('<img src="./img/loading2.gif" style="width:16px;height:16px;" align="rigth">Validando ...');
			var pass_crip = hex_md5(this.txtPass.getValue());
			var txtId = this.txtUsuario.getValue();
			//pass_crip='8e95c9596421079a5ee92b5c3eb41378';
			var conn=new Ext.data.Connection();
			conn.request({
						url:joshua.url,
						scope:this,
						params:{
                            cmd:'loguear',
                            className:'Session',
                            txtId:txtId,
                            pwd_pass:pass_crip
                        },
						callback:function(opt,success,response){						

							var respuesta = Ext.util.JSON.decode(response.responseText);
							
							if(respuesta.success){
								setTimeout( function (){window.location.href="index.php";},100);				 			
							}
							else{
								joshua.funciones.alert('delete','Acceso restringido',respuesta.error,'');
							} 
							this.getEl().unmask();
						}						
			});	
 	}
});//fin extenloginForm